home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / graphics / gnuplot / gnuplot.el < prev    next >
Lisp/Scheme  |  1993-09-15  |  6KB  |  151 lines

  1. ;;
  2. ;; $Id: gnuplot.el%v 3.50 1993/07/09 05:35:24 woo Exp $
  3. ;;
  4. ;;
  5. ; gnu-plot.el - Definitions of GNU-PLOT mode for emacs editor.
  6. ; Author:    Gershon Elber
  7. ;         Computer Science Dept.
  8. ;         University of Utah
  9. ; Date:    Tue May 14 1991
  10. ; Copyright (c) 1991, 1992, Gershon Elber
  11. ;
  12. ; This file defines an environment to run edit and execute GNU-PLOT programs.
  13. ; Such a program should have a '.gp' extension in order it to be in
  14. ; gnu-plot-mode major mode. Two new functions are provided to communicate
  15. ; between the editted file and the plotting program:
  16. ; 1. send-line-to-gnu-plot - sends a single line to the plotting program for
  17. ;    execution. The line sent is the line the cursor is on,
  18. ;    Bounded to Meta-E by default.
  19. ; 2. send-region-to-gnu-plot - sends the region from the current mark
  20. ;    (mark-marker) to current position (point-marker) to the plotting program.
  21. ;    This function is convenient for sending a large block of commands.
  22. ;    Bounded to Meta-R by default.
  23. ; Both functions checks for existance of a buffer named gnu-plot-program
  24. ; and a process named "gnu-plot" hooked to it, and will restart a new process
  25. ; or buffer if none exists. The program to execute as process "gnu-plot" is
  26. ; defined by the gnu-plot-program constant below.
  27. ;
  28.  
  29. (defvar gnu-plot-program "gnuplot"
  30.   "*The executable to run for gnu-plot-program buffer.")
  31.  
  32. (defvar gnu-plot-echo-program t
  33.   "*Control echo of executed commands to gnu-plot-program buffer.")
  34.  
  35. (defvar gnu-plot-mode-map nil "")
  36. (if gnu-plot-mode-map
  37.     ()
  38.   (setq gnu-plot-mode-map (make-sparse-keymap))
  39.   (define-key gnu-plot-mode-map "\M-e" 'send-line-to-gnu-plot)
  40.   (define-key gnu-plot-mode-map "\M-r" 'send-region-to-gnu-plot))
  41.  
  42. ;;;
  43. ;;; Define the gnu-plot-mode
  44. ;;;
  45. (defun gnu-plot-mode ()
  46.   "Major mode for editing and executing GNU-PLOT files.
  47.  
  48. see send-line-to-gnu-plot and send-region-to-gnu-plot for more."
  49.   (interactive)
  50.   (use-local-map gnu-plot-mode-map)
  51.   (setq major-mode 'gnu-plot-mode)
  52.   (setq mode-name "Gnu-Plot")
  53.   (run-hooks 'gnu-plot-mode-hook))
  54.  
  55. ;;;
  56. ;;; Define send-line-to-gnu-plot - send from current cursor position to next
  57. ;;; semicolin detected.
  58. ;;;
  59. (defun send-line-to-gnu-plot ()
  60.   "Sends one line of code from current buffer to the GNU-PLOT program.
  61.  
  62. Use to execute a line in the GNU-PLOT plotting program. The line sent is
  63. the line the cursor (point) is on.
  64.  
  65. The GNU-PLOT plotting program buffer name is gnu-plot-program and the 
  66. process name is 'gnu-plot'. If none exists, a new one is created.
  67.  
  68. The name of the gnu-plot program program to execute is stored in
  69. gnu-plot-program variable and may be changed."
  70.   (interactive)
  71.   (if (equal major-mode 'gnu-plot-mode)
  72.     (progn
  73.       (make-gnu-plot-buffer)        ; In case we should start a new one.
  74.       (beginning-of-line)
  75.       (let ((start-mark (point-marker)))
  76.     (next-line 1)
  77.     (let* ((crnt-buffer (buffer-name))
  78.            (end-mark (point-marker))
  79.            (string-copy (buffer-substring start-mark end-mark)))
  80.       (switch-to-buffer-other-window (get-buffer "gnu-plot-program"))
  81.       (end-of-buffer)
  82.       (if gnu-plot-echo-program
  83.         (insert string-copy))
  84.       (set-marker (process-mark (get-process "gnu-plot")) (point-marker))
  85.       (if (not (pos-visible-in-window-p))
  86.         (recenter 3))
  87.       (switch-to-buffer-other-window (get-buffer crnt-buffer))
  88.       (process-send-region "gnu-plot" start-mark end-mark)
  89.       (goto-char end-mark))))
  90.     (message "Should be invoked in gnu-plot-mode only.")))
  91.  
  92. ;;;
  93. ;;; Define send-region-to-gnu-plot - send from current cursor position to
  94. ;;; current marker.
  95. ;;;
  96. (defun send-region-to-gnu-plot ()
  97.   "Sends a region of code from current buffer to the GNU-PLOT program.
  98.  
  99. When this function is invoked on an GNU-PLOT file it send the region
  100. from current point to current mark to the gnu-plot plotting program.
  101.  
  102. The GNU-PLOT plotting program buffer name is gnu-plot-program and the
  103. process name is 'gnu-plot'. If none exists, a new one is created.
  104.  
  105. The name of the gnu-plot program program to execute is stored in
  106. gnu-plot-program variable and may be changed."
  107.   (interactive)
  108.   (if (equal major-mode 'gnu-plot-mode)
  109.     (progn
  110.       (make-gnu-plot-buffer)     ; In case we should start a new one.
  111.       (copy-region-as-kill (mark-marker) (point-marker))
  112.       (let ((crnt-buffer (buffer-name)))
  113.     (switch-to-buffer-other-window (get-buffer "gnu-plot-program"))
  114.     (end-of-buffer)
  115.     (if gnu-plot-echo-program
  116.       (yank))
  117.     (set-marker (process-mark (get-process "gnu-plot")) (point-marker))
  118.     (if (not (pos-visible-in-window-p))
  119.       (recenter 3))
  120.     (switch-to-buffer-other-window (get-buffer crnt-buffer))
  121.     (process-send-region "gnu-plot" (mark-marker) (point-marker))))
  122.     (message "Should be invoked in gnu-plot-mode only.")))
  123.  
  124. ;;;
  125. ;;; Switch to "gnu-plot-program" buffer if exists. If not, creates one and
  126. ;;; execute the program defined by gnu-plot-program.
  127. ;;;
  128. (defun make-gnu-plot-buffer ()
  129.   "Switch to gnu-plot-program buffer or create one if none exists"
  130.   (interactive)
  131.   (if (get-buffer "gnu-plot-program")
  132.     (if (not (get-process "gnu-plot"))
  133.       (progn
  134.     (message "Starting GNU-PLOT plotting program...")
  135.     (start-process "gnu-plot" "gnu-plot-program" gnu-plot-program)
  136.     (process-send-string "gnu-plot" "\n")
  137.     (message "Done.")))
  138.     (progn
  139.       (message "Starting GNU-PLOT plotting program...")
  140.       (start-process "gnu-plot" "gnu-plot-program" gnu-plot-program)
  141.       (process-send-string "gnu-plot" "\n")
  142.       (message "Done."))))
  143.  
  144. ;;;
  145. ;;; Autoload gnu-plot-mode on any file with gp extension. 
  146. ;;;
  147. (setq auto-mode-alist (append '(("\\.gp$" . gnu-plot-mode))
  148.                   auto-mode-alist))
  149.